package com.goma.test;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Date;

import org.apache.log4j.Logger;

public class BroadCastSend {
    private static final Logger logger = Logger.getLogger(BroadCastSend.class);
    public static void main(String[] args) {
        try {
            InetAddress ip = InetAddress.getByName("255.255.255.255");
            DatagramSocket ds = new DatagramSocket();
            while (true) {

                String str = "Goma God Like." + new Date().getTime();
                DatagramPacket dp = new DatagramPacket(str.getBytes(), str.getBytes().length, ip, 3001);
                logger.info("broadcata: " + str);
                ds.send(dp);
                Thread.sleep(1000);
                // ds.close();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }// 创建用来发送数据报包的套接字
    }
}
